package mcsm.DataBaseIntegration;

import java.sql.SQLException;
import java.sql.Statement;

import mcsm.DataBaseInterface.DeleteOperation;
import mcsm.Model.ReturnUnit;

public class DeleteReturnUnitConnect implements DeleteOperation{

	private ReturnUnit returnUnit;
	
	private int returnNum;
	
	public DeleteReturnUnitConnect(ReturnUnit returnUnit) {
		this.returnUnit = returnUnit;
	}

	@Override
	public Boolean connect(Statement statement) {
		int i = 0;
		try {
			i = statement.executeUpdate(delete());
			statement.executeUpdate("update number set saleUnit = " + returnNum);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return (i != 0);
	}

	@Override
	public String delete() {
		DataBaseConnect database = DataBaseConnect.getDatabase();
		String id = returnUnit.getReturnUnitID();
		returnNum = database.getReturnUnitNumber() - 1;
		String sql = "delete from saleUnit where id = '" + id + "'";
		return sql;
	}

}
